package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.UserMessageDetailActivity;
import com.example.administrator.yuejian_2.bean.MessageBean;
import com.example.administrator.yuejian_2.viewholder.MessageListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */

public class MessageListAdapter extends RecyclerView.Adapter {
    private List<MessageBean> message = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public MessageListAdapter(Context context, List<MessageBean> message){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.message.addAll(message);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_message,parent,false);
        MessageListViewHolder holder = new MessageListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MessageListViewHolder messageholder = (MessageListViewHolder) holder;
        MessageBean messagelist = message.get(position);
        messageholder.name.setText(messagelist.getSystem_name());
        messageholder.message.setText(messagelist.getMessage());
        String picture = messagelist.getSystem_pic();
        if (!picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+picture)
                    .into(messageholder.pic);

        final int message_id = messagelist.getMessage_id();
        messageholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, UserMessageDetailActivity.class);
                intent.putExtra("message_id",message_id);
                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {

        return message.size();
    }
}

